package lab.chapter;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Token {
    // token 的类型
    private String type = null;

    // token 的文本
    private String text = null;

    // token 在整个字符串流中的起止位置
    private int startPos = 0;
    private int endPos = 0;

    // token所在的行列位置
    private int lineNumber = 0;
    private int startColumn = 0;
    private int endColumn = 0;

    // 结束符
    protected static Token EOF = new Token("$");

    public Token(String type) {
        this.type = type;
    }

    public Token(String type, String text) {
        this.type = type;
        this.text = text;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;

        Token token = (Token) object;
        if (!type.equals(token.type)) {
            return false;
        }

        if (text == null) {
            return token.text == null;
        } else {
            return text.equals(token.text);
        }
    }

    @Override
    public String toString() {
        String rtn = type;
        rtn += ":";
        if (text != null) {
            rtn += text;
        }
        return rtn;
    }
}
